#include <stdio.h>

void gnome_sort(int *a, int n)
{
  int i=1, j=2, t;
# define swap(i, j) { t = a[i]; a[i] = a[j]; a[j] = t; } 
  while(i < n) {
    if (a[i - 1] > a[i]) {
      swap(i - 1, i);
      if (--i) continue;
    }
    i = j++;
  }
# undef swap
}

int main()
{
   int a[11] = {10, 8, 4, 3, 1, 9, 0, 2, 7, 5, 6};
   printf("before: [");
   for (int i = 0; i < 10; ++i)
   {
     printf("%d ", a[i]);
   }
   printf("%d\n", a[11]);
   gnome_sort(a, 11);
   printf("after:  [");
   for (int i = 0; i < 10; ++i)
   {
     printf("%d ", a[i]);
   }
   printf("%d\n", a[11]);
   return 0;
}
